package admin

import (
	"bbs-go/internal/services"
	"time"

	"github.com/kataras/iris/v12"
	"github.com/mlogclub/simple/web"
	"github.com/mlogclub/simple/web/params"
)

type UserLoginLogController struct {
	Ctx iris.Context
}

// func (c *UserLoginLogController) GetBy(id int64) *web.JsonResult {
// 	t := services.UserFollowService.Get(id)
// 	if t == nil {
// 		return web.JsonErrorMsg("Not found, id=" + strconv.FormatInt(id, 10))
// 	}
// 	return web.JsonData(t)
// }

func (c *UserLoginLogController) AnyList() *web.JsonResult {
	// departmentId := c.Ctx.ResetQuery("departmentId")
	nickname := params.FormValue(c.Ctx, "nickname")
	list, paging, err := services.UserLoginLogService.GetUserLoginLogList(params.NewQueryParams(c.Ctx).PageByReq().Desc("id"), nickname)
	if err != nil {
		return web.JsonError(err)
	}
	for i, _ := range list {
		dateTime := time.Unix(list[i].LoginTime, 0)
		list[i].LoginTimeStr = dateTime.Format("2006-01-02 15:04:05")
	}
	return web.JsonData(&web.PageResult{Results: list, Page: paging})
}
